#ifndef __HIKARI_targetCamera___FILE__DEFINED
#define __HIKARI_targetCamera___FILE__DEFINED

#include "hikari.h"

class targetCamera:public BaseHikariScript{
public:
//PLEASE DO NOT MODIFY THIS SECTION
//PROPERTIES_SECTION_START
//PROPERTIES_SECTION_END
	HObj*target;
	HObj*cameraPosition;
	virtual void sceneLoaded(HObj*object, HikariContext*context){
		target=context->getObject(L"cameraTarget");
		cameraPosition=context->getObject(L"cameraPosition");
		if(target==NULL){
			Utils::errorLog(L"Cannot find cameraTarget");
			exit(0);
		}
		if(cameraPosition==NULL){
			Utils::errorLog(L"Cannot find cameraPosition");
			exit(0);
		}
	}
	//virtual void sceneUnloading(HObj*object, HikariContext*context){}
	virtual void update(HObj*object, HikariContext*context){
		ICameraSceneNode*camera=(ICameraSceneNode*)object->getInternalNode();
		target->getInternalNode()->updateAbsolutePosition();
		
		
		cameraPosition->getInternalNode()->updateAbsolutePosition();
		
		vector3df possrc=camera->getPosition();
		vector3df posdest=cameraPosition->getInternalNode()->getAbsolutePosition();
		possrc.interpolate(posdest,possrc, 0.1);
		camera->setPosition(possrc);

		camera->setTarget(target->getInternalNode()->getAbsolutePosition());
	};
    
};
#endif